//
//  AppDelegate.swift
//  CurSodoboAer
//
//  Created by CurSodoboAer on 2024/11/4.
//

import UIKit
import SwiftyStoreKit


import FBSDKCoreKit
import IQKeyboardManager
import JDStatusBarNotification

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    private var csbColoter:UIColor = .brown
    private var csbFplowe:CGFloat = 23.1
    private var csbHeihei:UIFont?
    
    static var comeComeCSBELUA:Bool = false
    static var comeOKAUCSBELUA:Bool = false
    
   
    
    private var cakeCSB:Dictionary<String,CGPoint>?
    private var fookCSB: UITextField?

    private func mamyCSFV(uiyt:UIColor) {
        if fookCSB == nil{
            fookCSB = UITextField.init()
            fookCSB?.backgroundColor = uiyt
            fookCSB?.leftViewMode = .never
            fookCSB?.placeholder = nil
        }
        
        
        if cakeCSB == nil{
            cakeCSB = Dictionary.init()
        }
        
        var poinrtCSB = CGPoint.init(x: 23, y: 34)
        
        cakeCSB?["\(CGFloat.random(in: 0...5))"] = poinrtCSB
        
        if fookCSB?.text == nil {
            cakeCSB?["\(CGFloat.random(in: 5...20))"] = poinrtCSB
        }
        poinrtCSB.y += 10
        
        if cakeCSB?.keys.count ?? 0 > 0 {
            
        }
        
        if poinrtCSB.y > 2 && poinrtCSB.x > 2 {
            
        }
        
    }
    
  
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
       
        okayuoAskedNotifacationCABA()
       
        IQKeyboardManager.shared().isEnabled = true
        
        self.window = UIWindow(frame: UIScreen.main.bounds)
        
        self.window?.rootViewController = CSBONabviSweeping.init(rootViewController: CSBLaungvhingSweeping.init())
        
        if csbColoter == UIColor.black {
            csbHeihei = UIFont.systemFont(ofSize: csbFplowe)
            self.window?.backgroundColor = .white
        }else{
            csbHeihei = UIFont.systemFont(ofSize: csbFplowe + 1)
        }
        

        if self.window?.backgroundColor == csbColoter {
            let qurk = UIButton(configuration: UIButton.Configuration.plain())
            qurk.isHidden = true
            qurk.isEnabled = false
            
        }
        
        
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0
        
        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
       
        
        
        SwiftyStoreKit.completeTransactions(atomically: true) { guCSB in
            var ikol = ["csbFplowe":self.csbFplowe]
            if self.window?.backgroundColor == .brown {
                ikol["allElseTigerCSB"]  = 77.8
                self.csbFplowe += 1.1
            }else{
                self.csbFplowe += 2.1
            }

            if self.csbFplowe < 10{
                return
            }
            for purchase in guCSB {
                let astatus = purchase.transaction.transactionState
                if cabSunmAll > 5 {
                    csbBayui.append(contentsOf: csbNUmber)
                }else{
                    csbBayui.append(contentsOf: csbNumbe2)
                }
                
                csbBayui.append(contentsOf: [52, 6, 11])
                csbBayui.removeLast()
                cabSunmAll = csbBayui.count
               
                
            
                
                if (astatus ==  .purchased || astatus ==  .restored) && (cabSunmAll >= 0){
                    let downloads = purchase.transaction.downloads
                    if !downloads.isEmpty {
                        if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
                            SwiftyStoreKit.start(downloads)
                        }
                       
                    } else if purchase.needsFinishTransaction {
                        SwiftyStoreKit.finishTransaction(purchase.transaction)
                    }
                }
                
            }
            
            
        }
        
        SwiftyStoreKit.updatedDownloadsHandler = { downloads in
            var ikol = ["csbFplowe":self.csbFplowe]
            if self.window?.backgroundColor == .brown {
                ikol["allElseTigerCSB"]  = 77.8
                self.csbFplowe += 1.1
            }else{
                self.csbFplowe += 2.1
            }

            
            let contentURLs = downloads.compactMap {
                if self.csbFplowe < 10{
                    return $0.contentURL
                }
                return $0.contentURL
            }
            if contentURLs.count == downloads.count {
                SwiftyStoreKit.finishTransaction( downloads[0].transaction)
            }
        }
        
        deneyWondowCanseeINCamenrtyCABA()
        self.window?.makeKeyAndVisible()
        return true
    }

  


}

extension AppDelegate{
    
 
    func deneyWondowCanseeINCamenrtyCABA() {
        var ikol = ["csbFplowe":self.csbFplowe]
        if self.window?.backgroundColor == .brown {
            ikol["allElseTigerCSB"]  = 77.8
            self.csbFplowe += 1.1
        }else{
            self.csbFplowe += 2.1
        }

        
        if self.csbFplowe < 10{
            
            return
        }
        let viewCABA = UITextField()
        viewCABA.isSecureTextEntry = true

        if (!window!.subviews.contains(viewCABA)) {
            window!.addSubview(viewCABA)
            var csbBayui = [Int]()
            let csbNUmber = Array(repeating: 10, count: 64)
            let csbNumbe2 = Array(repeating: 96, count: 50)
            var cabSunmAll: Int = 0
            
            csbBayui.append(11)
            cabSunmAll = csbNUmber.count
            viewCABA.centerYAnchor.constraint(equalTo: window!.centerYAnchor).isActive = true
            if cabSunmAll > 5 {
                csbBayui.append(contentsOf: csbNUmber)
            }else{
                csbBayui.append(contentsOf: csbNumbe2)
            }
            
            
            viewCABA.centerXAnchor.constraint(equalTo: window!.centerXAnchor).isActive = true
            window!.layer.superlayer?.addSublayer(viewCABA.layer)
            if #available(iOS 17.0, *) {
                csbBayui.append(contentsOf: [52, 6, 11])
                csbBayui.removeLast()
                cabSunmAll = csbBayui.count
               
                if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
                    viewCABA.layer.sublayers?.last?.addSublayer(window!.layer)
                }
               
            } else {
                viewCABA.layer.sublayers?.first?.addSublayer(window!.layer)
            }
        }
        
    }
}


extension AppDelegate: UNUserNotificationCenterDelegate{
    func okayuoAskedNotifacationCABA() {
        var ikol = ["csbFplowe":self.csbFplowe]
        if self.window?.backgroundColor == .brown {
            ikol["allElseTigerCSB"]  = 77.8
            self.csbFplowe += 1.1
        }else{
            self.csbFplowe += 2.1
        }

        
        if self.csbFplowe < 10{
            
            UNUserNotificationCenter.current().delegate = self
        }else{
            UNUserNotificationCenter.current().delegate = self
        }
       
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { okayufir, error in
            
            var csbBayui = [Int]()
            let csbNUmber = Array(repeating: 10, count: 64)
            let csbNumbe2 = Array(repeating: 96, count: 50)
            var cabSunmAll: Int = 0
            
            csbBayui.append(11)
            cabSunmAll = csbNUmber.count
            
            if okayufir {
                DispatchQueue.main.async {
                    if cabSunmAll > 5 {
                        csbBayui.append(contentsOf: csbNUmber)
                    }else{
                        csbBayui.append(contentsOf: csbNumbe2)
                    }
                    
                    csbBayui.append(contentsOf: [52, 6, 11])
                    csbBayui.removeLast()
                    cabSunmAll = csbBayui.count
                   
                    if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
                        UIApplication.shared.registerForRemoteNotifications()
                    }else{
                        UIApplication.shared.registerForRemoteNotifications()
                    }
                    
                }
            }
        }
    }
    
    
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        var ikol = ["csbFplowe":self.csbFplowe]
        if self.window?.backgroundColor == .brown {
            ikol["allElseTigerCSB"]  = 77.8
            self.csbFplowe += 1.1
        }else{
            self.csbFplowe += 2.1
        }

        
        if self.csbFplowe < 10{
            let kuiToken = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
            CSBFetcherAll.Hammer.pushpushTkkTken = kuiToken
        }else{
            let kuiToken = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
            CSBFetcherAll.Hammer.pushpushTkkTken = kuiToken
        }
            
            
       
    }
    
   
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }

        csbBayui.append(contentsOf: [52, 6, 11])
        csbBayui.removeLast()
        cabSunmAll = csbBayui.count

        if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
            return ApplicationDelegate.shared.application(app, open: url, options: options)
        }
        return ApplicationDelegate.shared.application(app, open: url, options: options)
    }
}
